function obj_eval = obj_function(param_unc,fp)
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;
%To constraint the structural parameters;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;

%Technology (Cobb-Douglas, PS=1);
param_con(1) = exp(param_unc(1)/100);    %Children's skills (alpha1);
param_con(2) = exp(param_unc(2)/100);    %Peers' Skills (alpha2);
param_con(3) = exp(param_unc(3)/100);    %Investments (alpha3);


param_con(4) = param_unc(4)/100;         %Parenting Style (alpha0);

%Technology (CES, PS=0);
param_con(5) = exp(param_unc(5)/100)./(1 + exp(param_unc(5)/100) );         %CES Elasticity (   Parents vs Peers, inner)
param_con(6) = exp(param_unc(6)/100)./(1 + exp(param_unc(6)/100) );         %CES Share Skills ;
param_con(7) = exp(param_unc(7)/100)./(1 + exp(param_unc(7)/100) );         %CES Share Peers;
param_con(8) = -exp(param_unc(8)/100) ;                                     %CES Elasticity ( Skills vs Parents-Peers, outer);
param_con(9) = param_unc(9)/100 ;                                           %Return to Scale CES;

param_con(10) = param_unc(10)/100;           %TFP constant;
param_con(11) = param_unc(11)/100;           %TFP trend;

ind  = 11 ;

%Parent's Preferences;

param_con(ind+1) =      exp(param_unc(ind+1)/100);                    %Weight on Children's Skills;
param_con(ind+2) =      param_unc(ind+2)/100 ;                        %Disutility of PS;
param_con(ind+3) =      param_unc(ind+3)/100 ;                        %Heterogeneity in PS;

ind  = ind + 3 ;

%Child's Preferences;

param_con(ind+1) =  param_unc(ind+1)/100;                       %Constant (gamma0);
param_con(ind+2) =  param_unc(ind+2)/100;                       %Own Skills (gamma1);
param_con(ind+3) =  param_unc(ind+3)/100;                       %Child j 's Skills (gamma2);
param_con(ind+4) =  param_unc(ind+4)/100;                       %Homophily (gamm3);
param_con(ind+5) =  param_unc(ind+5)/100;                       %PS effect (gamma4);


param_con(ind+6) =      param_unc(ind+6)/100 ;                        %Disutility of PS (by Neighborhood Income);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Simulate latent variables from latent parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
               
sim = sim_data_function(param_con,fp) ;


simul_data = sim.sim_data ; 
sim_data_network = sim.sim_data_network;

toc


 
if fp.do_counter == 0

Value0     =    sim.Value0;
Value1     =    sim.Value1;

obj_eval.Value0= Value0;
obj_eval.Value1= Value1;

end

obj_eval.structural_params = param_con;    
obj_eval.simul_data= simul_data;
obj_eval.sim_data_network=sim_data_network;

if fp.do_counter    == 1 && fp.do_counter_type<4
obj_eval.id_moved_children = sim.id_moved_children;
obj_eval.id_flights        = sim.id_flights;
end








